import asyncio
import websockets

async def hello(id):
    uri = "ws://localhost:8899"
    async with websockets.connect(uri) as websocket:    #使用多个socket链接
        await websocket.send(f"Hello, world! {id}")
        response = await websocket.recv()
        print(f"Received: {response}")

async def main():
    tasks = [hello(id) for id in range(10)]  # create 10 tasks
    await asyncio.gather(*tasks)

if __name__ == "__main__":
    asyncio.run(main())